package com.hhkj.admin.sale.service.biz.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.hhkj.admin.order.common.cont.OrderConst;
import com.hhkj.admin.order.domain.OrderItem;
import com.hhkj.admin.sale.common.cont.SaleCommissionConst;
import com.hhkj.admin.sale.common.cont.SaleWithdrawalConst;
import com.hhkj.admin.sale.domain.SaleWithdrawal;
import com.hhkj.admin.sale.model.dopo.SaleCommissionPo;
import com.hhkj.admin.sale.model.dopo.SaleWithdrawalDo;
import com.hhkj.admin.sale.model.dopo.SaleWithdrawalPo;
import com.hhkj.admin.sale.model.req.SaleWithdrawalReq;
import com.hhkj.admin.sale.model.res.SaleWithdrawalRes;
import com.hhkj.admin.sale.service.base.SaleWithdrawalService;
import com.hhkj.admin.sale.service.biz.SaleWithdrawalBizService;
import com.hhkj.admin.sale.service.extend.SaleWithdrawalExtendService;
import com.ruoyi.common.base.biz.service.biz.BaseBizService;
import com.ruoyi.common.base.biz.service.biz.BaseBizServiceImpl;
import com.ruoyi.common.utils.excl.model.ExcelCreateModel;
import com.ruoyi.common.utils.excl.utils.ExcelUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SaleWithdrawalBizServiceImpl extends BaseBizServiceImpl<SaleWithdrawal, SaleWithdrawalReq, SaleWithdrawalRes, SaleWithdrawalDo, SaleWithdrawalPo, SaleWithdrawalService, SaleWithdrawalExtendService> implements SaleWithdrawalBizService {
    @Override
    public Workbook createExportWorkbook(SaleWithdrawalReq saleWithdrawalReq) {
        List<SaleWithdrawalPo> saleWithdrawalPoList = this.getService().listPoByDo(saleWithdrawalReq);
        String suffix = "";
        if (ObjectUtil.isNotEmpty(saleWithdrawalReq.getWithdrawalDateStart()) && ObjectUtil.isNotEmpty(saleWithdrawalReq.getWithdrawalDateEnd())) {
            suffix = " 支付日期：" + DateUtil.format(saleWithdrawalReq.getWithdrawalDateStart(), "yyyy-MM-dd") + " - " + DateUtil.format(saleWithdrawalReq.getWithdrawalDateEnd(), "yyyy-MM-dd");
        }
        Workbook template = ExcelUtils.createExcelWorkbookSheetNumber(new ExcelCreateModel(
                SaleWithdrawalConst.EXPORT_EXCEL_TITLE,
                SaleWithdrawalConst.EXPORT_EXCEL_TITLE + suffix,
                saleWithdrawalPoList,
                SaleWithdrawalPo.class));
        return template;
    }
}
